package sgi.client;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

import sgi.user.User;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SGIComplaintUI extends JFrame {

	private JPanel contentPane;
	private JTextField txtReasonForComplaint;
	private JTextArea textArea;
	private JTextArea textAreaDescription;
	private JScrollPane scrollPane;
	private JComboBox comboBox;
	private SGIComplaintController complaintController;
	private User user;



	public SGIComplaintUI(User user) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setLayout(null);
		setTitle("SGI Complaint "+user.getUsername());
		setContentPane(contentPane);
		
		user = new User(user);
		
		comboBox = new JComboBox();
		comboBox.setBounds(20, 11, 390, 20);
		comboBox.addItem("Select type...");
		comboBox.addItem("Employee behavior");
		comboBox.addItem("Insufficient content");
		comboBox.addItem("Prices");
		comboBox.addItem("Other");
		contentPane.add(comboBox);
		
		txtReasonForComplaint = new JTextField();
		txtReasonForComplaint.setText("Reason for complaint.");
		txtReasonForComplaint.setBounds(20, 42, 390, 20);
		txtReasonForComplaint.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseClicked(MouseEvent e){
            	txtReasonForComplaint.setText("");
            }
        });
		contentPane.add(txtReasonForComplaint);
		txtReasonForComplaint.setColumns(10);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(20, 73, 390, 138);
		contentPane.add(scrollPane);
		
		textAreaDescription = new JTextArea("Description...");
		textAreaDescription.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseClicked(MouseEvent e){
            	textAreaDescription.setText("");
            }
        });
		scrollPane.setColumnHeaderView(textAreaDescription);
		
		
		JButton btnSubmit = new JButton("Submit");
		btnSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(comboBox.getSelectedIndex() == 0)
					JOptionPane.showMessageDialog(SGIComplaintController.getUI(),"Choose complaint type.");
				else
					complaintController.submitComplaint(comboBox.getSelectedIndex(),txtReasonForComplaint.getText(),textAreaDescription.getText());
			}
		});
		btnSubmit.setBounds(321, 222, 89, 23);
		contentPane.add(btnSubmit);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				SGIComplaintController.terminate();
				SGIUserAccountMenuController.create(null);
			}
		});
		btnCancel.setBounds(20, 222, 89, 23);
		contentPane.add(btnCancel);
	}
	
	public int getTypeComplaint()
	{
		return comboBox.getSelectedIndex();
	}
	
	public String getReason()
	{
		return txtReasonForComplaint.getText();
	}
	
	public String getDescription()
	{
		return textAreaDescription.getText();
	}
	
	public void notify(String str)
	{
		JOptionPane.showMessageDialog(this,str);
	}

	public SGIComplaintController getComplaintController() {
		return complaintController;
	}

	public void setComplaintController(SGIComplaintController complaintController) {
		this.complaintController = complaintController;
	}
}
